package ph.com.gs3.formalistics;

import ph.com.gs3.formalistics.global.constants.GlobalConstants;
import ph.com.gs3.formalistics.global.utilities.logging.FLLogger;
import ph.com.gs3.formalistics.global.utilities.logging.FLPersistentLogger;
import ph.com.gs3.formalistics.model.communicators.AuthenticationCommunicatorModule;
import ph.com.gs3.formalistics.model.communicators.HttpCommunicator;
import ph.com.gs3.formalistics.model.dao.UserAccountsDAO;
import ph.com.gs3.formalistics.service.managers.SessionManager;
import android.app.Application;

public class MainApplication extends Application {

	@Override
	public void onCreate() {
		super.onCreate();

		initializeSingletons();

		FLLogger.setPersistentLogger(new FLPersistentLogger(getApplicationContext()));
		FLLogger.setTraceEnabled(false);

		GlobalConstants.createApplicationInstace(getApplicationContext());
	}

	private void initializeSingletons() {

		// initialize communicator dependent managers

		HttpCommunicator communicator = new HttpCommunicator();
		AuthenticationCommunicatorModule authCommModule = new AuthenticationCommunicatorModule(
		        communicator);

		UserAccountsDAO userAccountsDAO = new UserAccountsDAO(getApplicationContext());

		SessionManager sessionManager = SessionManager.createApplicationInstance(
		        getApplicationContext(), userAccountsDAO, authCommModule);

		sessionManager.startListeningToNetworkChanges();

	}

}
